<?php

/**
 * Class Involved_MessageModel
 */

class Involved_MessageModel extends BaseModel{

    protected $table = 'message';

    public function MyMessageInfo($user_id,$page,$status){
        $limit = ($page-1)*10;
        return DB::table($this->table)
            ->where('user_id',$user_id)
            ->where('status',$status)
            ->orderBy('created','desc')
            ->skip($limit)->take(10)
            ->get();
    }
    public function PlatformMessageInfo($user_id,$page,$status){
        $limit = ($page-1)*10;
        return DB::table($this->table)
            ->where('user_id',$user_id)
            ->where('status',$status)
            ->orderBy('created','desc')
            ->skip($limit)->take(10)
            ->get();
    }

    /**
     * 单条查询最新消息
     * @param $user_id
     * @return mixed
     */
    public function MyMessageOne($user_id){
        return DB::table($this->table)
            ->where('user_id',$user_id)
            ->where('status',1)
            ->orderBy('created','desc')
            ->first();
    }
    public function PlatformMessageOne($user_id){
        return DB::table($this->table)
            ->where('user_id',$user_id)
            ->where('status',2)
            ->orderBy('created','desc')
            ->first();
    }
    public function UserMessage($user_id,$status){
        return DB::table($this->table)
            ->where('user_id',$user_id)
            ->where('status',$status)
            ->get();
    }

    /**
     * @param $user_id
     * @param $status
     * @return mixed
     */
    public function ShopMyMessageInfo($user_id,$status){
        return DB::table($this->table)
            ->where('user_id',$user_id)
            ->where('status',$status)
            ->orderBy('created','desc')
            ->get();
    }

    /**
     * @param $user_id
     * @return mixed
     */
    public function MessageCount($user_id){
        return DB::table($this->table)
            ->where('user_id',$user_id)
            ->where('is_look',0)
            ->count();
    }

    /**
     * 后台系统通知列表
     * @return mixed
     */
    public function MessageList(){
        return DB::table($this->table)
            ->select('title','content','created')
            ->where('status',2)
            ->groupBy('created')
            ->get();
    }

}